// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#ifndef ROTHAR_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP
#define ROTHAR_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP

#include <string>

#include <rothar/pegtl/change_action_and_states.hpp>
#include <rothar/pegtl/contrib/json.hpp>
#include <rothar/pegtl/contrib/unescape.hpp>

namespace example
{
   // Action class for parsing literal strings, uses the PEGTL unescape utilities, cf. unescape.cpp.

   // clang-format off
   template< typename Rule > struct json_unescape_action {};

   template<> struct json_unescape_action< rothar::json::unicode > : rothar::unescape::unescape_j {};
   template<> struct json_unescape_action< rothar::json::escaped_char > : rothar::unescape::unescape_c< rothar::json::escaped_char, '"', '\\', '/', '\b', '\f', '\n', '\r', '\t' > {};
   template<> struct json_unescape_action< rothar::json::unescaped > : rothar::unescape::append_all {};
   // clang-format on

   using json_unescape = rothar::change_action_and_states< json_unescape_action, std::string >;

}  // namespace example

#endif
